package servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Contact;
import model.ContactGroup;
import model.ContactGroupManager;

/**
 * Servlet implementation class AddGroup
 */
public class AddGroup extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddGroup() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String groupName = (String)request.getParameter("newGroupName");
		System.out.println("ContactList get request : "+request.toString()+" groupName : "+groupName);
		ContactGroup newGroup = new ContactGroup(groupName);
		ContactGroupManager.getInstance().addGroup(newGroup);
		ContactGroupManager.getInstance().saveGroup(newGroup);
		
		request.getRequestDispatcher("Main").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
